﻿#nullable enable

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PHMEE.Controllers;
using Volo.Abp.Application.Dtos;

namespace PHMEE.EnergyEfficiency;

/// <summary>
/// 航海日志 Log abstract
/// </summary>
[Route("api/cbm/log-abstract")] 
public class LogAbstractController : PHMEEController, ILogAbstractAppService
{
    private readonly ILogAbstractAppService _logAbstractAppService;

    public LogAbstractController(ILogAbstractAppService logAbstractAppService)
    {
        _logAbstractAppService = logAbstractAppService;
    }

    /// <summary>
    /// 获取该船舶使用的油品
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("GetFuelTypes")] 
    [HttpGet]
    public Task<List<FuelType>> GetFuelTypesAsync(Guid vesselId)
    {
        return _logAbstractAppService.GetFuelTypesAsync(vesselId);
    }

    /// <summary>
    /// 检查航海日志 Log abstract 的时间戳是否已经存在
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="dateUTC"></param>
    /// <param name="timeUTC"></param>
    /// <returns></returns>
    [Route("CheckTsExist")] 
    [HttpPost]
    public Task<CheckTsExistDto> CheckTsExistAsync(Guid vesselId, [Required] DateOnly dateUTC,
        [Required] TimeOnly timeUTC)
    {
        return _logAbstractAppService.CheckTsExistAsync(vesselId, dateUTC, timeUTC);
    }

    /// <summary>
    /// 获取创建 log abstract 的 DTO
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="dateUTC"></param>
    /// <param name="timeUTC"></param>
    /// <returns></returns>
    [Route("GetCreateLogAbstractDto")]
    [HttpGet]
    public Task<LogAbstractDto> GetCreateLogAbstractDtoAsync(Guid vesselId, [Required] DateOnly dateUTC, [Required] TimeOnly timeUTC)
    {
        return _logAbstractAppService.GetCreateLogAbstractDtoAsync(vesselId, dateUTC, timeUTC);
    }

    /// <summary>
    /// 录入航海日志 Log abstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="input"></param>
    [Route("Create")]
    [HttpPost]
    public Task CreateAsync(Guid vesselId, [Required] LogAbstractDto input)
    {
        return _logAbstractAppService.CreateAsync(vesselId, input);
    }

    /// <summary>
    /// 删除航海日志 Log abstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="ts"></param>
    [Route("Delete")]
    [HttpDelete]
    public Task DeleteAsync(Guid vesselId, [Required] DateTime ts)
    {
        return _logAbstractAppService.DeleteAsync(vesselId, ts);
    }

    /// <summary>
    /// 更新航海日志 Log abstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="input"></param>
    [Route("Update")]
    [HttpPut]
    public Task UpdateAsync(Guid vesselId, LogAbstractDto input)
    {
        return _logAbstractAppService.UpdateAsync(vesselId, input);
    }

    /// <summary>
    /// 分页查询航海日志 Log abstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="input"></param>
    /// <returns></returns>
    [Route("GetList")]
    [HttpGet]
    public Task<PagedResultDto<LogAbstractDto>> GetListAsync(Guid vesselId,
        [Required] PagedAndSortedWithTimeRangeResultRequestDto input)
    {
        return _logAbstractAppService.GetListAsync(vesselId, input);
    }

    /// <summary>
    /// 根据输入的字符串匹配港口列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [Route("GetPorts")]
    [HttpGet]
    public Task<List<OVDPortDto>> GetPortsAsync(string input)
    {
        return _logAbstractAppService.GetPortsAsync(input);
    }
}